<template>
  <div class="report-form-content">
    <van-tabs :active="active1" type="card" :animated="true" :swipeable="true">
      <van-tab title="合同验收">
        <van-tabs :active="active2">
          <van-tab title="验收详情">
            <div class="report-form-list-content">
              <div class="shenpilist">
                <label>验收内容：</label>
                <span>{{ obj.content }}</span>
              </div>
              <div class="shenpilist">
                <label>验收负责人：</label>
                <span>{{ showIdLabel(userList, obj.principalUserId, 'name') }}</span>
              </div>
              <div class="shenpilist">
                <label>监理：</label>
                <span>{{ showIdLabel(userList, obj.supervisorUserId, 'name') }}</span>
              </div>
              <div class="shenpilist">
                <label>验收时间：</label>
                <span>{{ obj.checkingTime }}</span>
              </div>
              <div class="shenpilist">
                <label>验收意见：</label>
                <span>{{ obj.checkingComment }}</span>
              </div>
              <div class="shenpilist">
                <label>审批方式：</label>
                <span>{{ obj.approvalMethod === '1' ? '线上审批' : '线下审批' }}</span>
              </div>
              <div class="shenpilist">
                <label>验收状态：</label>
                <span><EnumTag :enum-list="getDictList('ContractInitialCheckingState')" :enum-key="obj.state" /></span>
              </div>
            </div>
          </van-tab>
          <!--item1.attachmentType === '01'-->
          <van-tab title="附件">
            <van-divider :style="{ color: '#1989fa', borderColor: '#1989fa', padding: '10px 16px' }" >验收附件</van-divider>
            <ul class="files-list" v-if="oFile.length > 0 && isfile1">
              <li v-for="item in oFile" :key="item.id" v-show="item.attachmentType === '01'">
                <div class="files-list-1">
                  <div class="files-list-content">
                    <p><span class="list-content-hindline">{{ item.attachmentName }}</span> {{ bytesToSize(item.attachmentSize) }}</p>
                    <p><span>上传于 {{ item.createTime }}</span></p>
                  </div>
                </div>
              </li>
            </ul>
            <van-empty description="暂无验收附件" v-else />
            <van-divider :style="{ color: '#1989fa', borderColor: '#1989fa', padding: '0 16px' }" v-if="oFile.length > 0 && obj.approvalMethod === '1'">签名/盖章附件</van-divider>
            <ul class="files-list" v-if="oFile.length > 0 && isfile2">
              <li v-for="item in oFile" :key="item.id" v-show="item.attachmentType === '02'">
                <div class="files-list-1">
                  <div class="files-list-content">
                    <p><span class="list-content-hindline">{{ item.attachmentName }}</span> {{ bytesToSize(item.attachmentSize) }}</p>
                    <p><span>上传于 {{ item.createTime }}</span></p>
                  </div>
                </div>
              </li>
            </ul>
            <van-empty description="签名/盖章附件" v-if="(oFile.length === 0 || !isfile2) && obj.approvalMethod === '1'" />
            <van-divider :style="{ color: '#1989fa', borderColor: '#1989fa', padding: '0 16px' }" v-if="oFile.length > 0 && obj.approvalMethod === '1'">验收结果附件</van-divider>
            <ul class="files-list" v-if="oFile.length > 0 && isfile3">
              <li v-for="item in oFile" :key="item.id"  v-show="item.attachmentType === '03'">
                <div class="files-list-1">
                  <div class="files-list-content">
                    <p><span class="list-content-hindline">{{ item.attachmentName }}</span> {{ bytesToSize(item.attachmentSize) }}</p>
                    <p><span>上传于 {{ item.createTime }}</span></p>
                  </div>
                </div>
              </li>
            </ul>
            <van-empty description="暂无验收结果附件" v-if="(oFile.length === 0 || !isfile3) && obj.approvalMethod === '1'" />
          </van-tab>
        </van-tabs>
      </van-tab>
      <van-tab title="合同详情">
        <contractMainDetail :contractInitialId="obj.contractInitialId" />
      </van-tab>
    </van-tabs>
  </div>
</template>
<script setup>
import {ref, watch} from 'vue'
import {doGet} from "@/config/http";
import {svc, showIdLabel, getListPageSize} from "@/config/common";
import contractMainDetail from '@/h5/components/contractMainDetail.vue'
import initListStore from '@/store/modules/initList'

const props = defineProps({
  contractCheckingId: {
    required: true,
    type: String,
  }
})
let active1 = ref(0)
let active2 = ref(0)
let obj = ref(null)
let oFile = ref([])

let isfile1 = ref(false)
let isfile2 = ref(false)
let isfile3 = ref(false)

let userList = initListStore().userList // 用户

// const initList = async () => {
//   let p1 = doGet(svc, '/user/page', {pageSize: getListPageSize()}, false) // 用户
//   let resArray = await Promise.all([p1])
//   userList.value = resArray[5]['records']
// }

const initObj = async (val) =>  {
  if (val) {
    obj.value = await doGet(svc, `/contract-initial-checking/${val}`, {}, true)
    oFile.value = await doGet(svc, '/contract-initial-checking-attachment/listByField', {field: 'contractInitialCheckingId', values: obj.value.id}, false)
    isfile1.value = oFile.value.every(item => item.attachmentType === '01')
    isfile2.value = oFile.value.every(item => item.attachmentType === '02')
    isfile3.value = oFile.value.every(item => item.attachmentType === '03')
  }
}

watch(() => props.contractCheckingId, async val => {
  await initObj(val)
  // await initList()
},{immediate:true})

</script>

<style scoped lang="scss">
.report-form-content {
  width: 100%;
  height: 52vh;
  overflow-x: hidden;
  overflow-y: auto;
  margin-top: 1.25rem;
}
.update-log {
  width: 100%;
  margin: 30px 0;
}
.tabs-form-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.tabs-form-head span {
  font-size: 18px;
  color: #303133;
  font-weight: bold;
}
.shenpilist {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--van-cell-background);
  box-sizing: border-box;
  width: 100%;
  padding: var(--van-cell-vertical-padding) var(--van-cell-horizontal-padding);
  overflow: hidden;
  color: var(--van-cell-text-color);
  font-size: var(--van-cell-font-size);
  // line-height: var(--van-cell-line-height);
  border-bottom: 1px solid var(--van-border-color);;
  & label {
    color: var(--van-field-label-color);
    // text-align: left;
    word-wrap: break-word;
    font-weight: 700;
  }
  & span {
    display: block;
    box-sizing: border-box;
    // width: 100%;
    color: var(--van-field-input-text-color);
    line-height: inherit;
    // text-align: left;
    background-color: transparent;
    border: 0;
    resize: none;
    -webkit-user-select: auto;
    user-select: auto;
  }
}
</style>
